<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="java.math.*,com.gouwudai.gobbs.pojo.TbbsClass,com.gouwudai.gobbs.pojo.TbbsUserInfo,com.gouwudai.gobbs.pojo.TbbsUserDetail,com.gouwudai.gobbs.pojo.TbbsTopic,com.gouwudai.gobbs.pojo.TbbsTopicRe" %>
<%@ include file="../common/common.jsp" %>
<%@ include file="user_pass.jsp" %>
<%
String action = ParamUtils.getStringParameter(request,"action","browse");	//浏览(browse)、结帖(balance)
int pageIndex = ParamUtils.getIntParameter(request, "pageIndex", 1);
int pageReSize = 10;

int classId = ParamUtils.getIntParameter(request, "classId", 0);
int topicId =  ParamUtils.getIntParameter(request,"topicId");
int topicReId =  ParamUtils.getIntParameter(request,"topicReId");

int classStyle = 0; //展现样式：BBS还是讨论区风格
if(userLogin.getUserStyle()!=null) //如果用户登陆时设定过样式，则按照用户设置
	classStyle = userLogin.getUserStyle().intValue();
if(request.getParameter("classStyle")!=null)	//如果用户又选择了样式，则按选择的来
{
	classStyle = ParamUtils.getIntParameter(request, "classStyle");
	userLogin.setUserStyle(new Integer(classStyle));	
}

IClassService classService = (IClassService)BeanManager.getBean("classService");
TbbsClass currentClass = null;
/***************** 权限验证模块 START *********************/
//判断当前版面是否存在
try
{
	currentClass = classService.load(new Integer(classId));
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的版面不存在或已被删除！");
	return;
}
//判断当前主题是否存在
ITopicService topicService = (ITopicService)BeanManager.getBean("topicService");
TbbsTopic tbbsTopic = null;

try
{
	tbbsTopic = topicService.load(new Integer(topicId));	
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的主题不存在或已被删除！");
	return;
}
//判断用户类型
IClassUserService classUserService = (IClassUserService)BeanManager.getBean("classUserService");
int operatorType = 0;//当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
if(classUserService.isClassManager(new Integer(classId),USER_ID))	//验证用户是否为版主
{
	operatorType = 2;
}
else if(0==USER_ID.intValue())	//游客
{
	operatorType = -1;
}
else if(tbbsTopic.getUserId().intValue()==USER_ID.intValue())	//验证用户是否为作者
{
	operatorType = 1;
}


if(operatorType!=2&&operatorType!=1) //非版主、作者用户
{
	//如果该主题未被审核且当前用户不是发帖人或版主，不能浏览
	if(!tbbsTopic.getTopicIsPass().booleanValue())
	{
		HtmlConst.errors(out,4,"您浏览的主题尚未被审核！");	
		return;
	}	
	//判断当前用户是否有浏览版面所需的等级
	if(userLogin.getGradeId().intValue()<currentClass.getAccessGrade().intValue())
	{
		HtmlConst.errors(out,1,"您的级别（"+ Arguments.getUserGradeName(userLogin.getGradeId()) +"）不能进行此项操作，如果你还没有登陆，请先登陆！");
		return;
	}	
	//如果该版面已被锁定，不能浏览
	if(currentClass.getClassPro().intValue()==2)
	{
		HtmlConst.errors(out,9,"该版面已被锁定！");
		return;
	}
	//如果该版面需要认证
	if(currentClass.getClassPro().intValue()==3)
	{
		boolean authFlag = classUserService.hasClassAuth(new Integer(classId),userLogin.getUserId());
		if(!authFlag)	
		{
			HtmlConst.errors(out,9,"该分类/版面需要认证！若需要浏览，请联系斑竹");
			return;
		}	
	}
	//判断主题状态
	if(tbbsTopic.getTopicPro().intValue()==1) //如果该主题已被锁定，不能浏览
	{
		HtmlConst.errors(out,9,"该主题已被锁定！");
		return;
	}	
	else if(tbbsTopic.getTopicPro().intValue()==4) //如果该主题已被禁止显示，不能浏览
	{
		HtmlConst.errors(out,9,"该主题已被禁止显示！");
		return;
	}
	
	//判断当前用户是否在黑名单当中
	if(operatorType==0)	//已登陆用户
	{
		IBlackListService blackListService = (IBlackListService)BeanManager.getBean("blackListService");
		String blackInfo = blackListService.isBlack(classId,USER_ID,3);//禁止浏览主题黑名单
		if(!blackInfo.equals(""))
		{			
			HtmlConst.errors(out,10,blackInfo);
			return;
		}		
	}
	//结帖操作的权限验证
	if(action.equals("balance"))	
	{
		//游客是无法结帖的
		if(operatorType==-1)
		{	
			HtmlConst.errors(out,1,"您尚未登陆，无权进行此项操作！点击<a href=\"user_login_iframe2.jsp?TB_iframe=true&height=300&width=450\"  title=\"用户登陆\" class=\"thickbox\">此处</a>登陆");
			return;	
		}
		else
		{
			//当前用户不是该主题的作者或管理员
			if(operatorType!=1||operatorType!=2)
			{
				HtmlConst.errors(out,4,"您不是该主题的作者，无权进行此项操作！");
				return;
			}
		}
	}	
}	
/***************** 权限验证模块 END *********************/
//------------------- 拼导航菜单 -----------------
//分类相关属性
String className = currentClass.getClassName();
//目前支持3级栏目
Integer parentId = currentClass.getParentId();//父栏目ID，如果不为空则说明有父栏目
String parentName = "";
TbbsClass parentClass = null;
Integer grandId = null;//二级父栏目ID，如果不为空则说明有父栏目
String grandName = "";
TbbsClass grandIdClass = null;
if(parentId!=null&&parentId.intValue()>0)
{
	parentClass = classService.load(parentId);	
	parentName = parentClass.getClassName();
	grandId = parentClass.getParentId();
}
if(grandId!=null&&grandId.intValue()>0)
{
	grandIdClass = classService.load(grandId);	
	grandName = grandIdClass.getClassName();
}

StringBuilder totalClassName = new StringBuilder(50);//栏目全名，包括父栏目
if(grandId!=null&&grandId.intValue()>0)
{
	totalClassName.append(grandIdClass.getClassName());
	totalClassName.append(" - ");
}
if(parentId!=null&&parentId.intValue()>0)
{
	totalClassName.append(parentClass.getClassName());
	totalClassName.append(" - ");
}
totalClassName.append(currentClass.getClassName());
//--------------------- 拼导航菜单 ----------------------------
IUserService userService = (IUserService)BeanManager.getBean("userService");
String queryCond = "classId="+classId+"&topicId="+topicId+"&topicReId="+topicReId;
if(action.equals("balance"))
{	
	queryCond += "&action=balance";	
}	

topicService.updateTopicViewCount(topicId);	//主题浏览次数加1
int topicType = tbbsTopic.getTopicType().intValue();//主题相关属性
BigDecimal remainMark = tbbsTopic.getTopicTypeNum();	//散分时剩余可散的分数
//查询主题的回复
ITopicReService topicReService = (ITopicReService)BeanManager.getBean("topicReService");
TbbsTopicRe tbbsTopicRe = null;
List reList = topicReService.listByTopic(topicId,pageIndex,pageReSize);
int totalReCount = topicReService.listCountByTopic(new Integer(topicId));	//主题回复数量
String pageUrl = "topic_page.jsp?"+queryCond+"&";
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=SYSTITLE%> - <%=tbbsTopic.getTitle()%></title>
<meta name="Keywords" content="<%=SYSMETAKEY%>" />
<meta name="Description" content="<%=SYSMETADESC%>" />
<%@ include file="../common/meta.inc" %>
<link rel="stylesheet" type="text/css" href="css/defaultStyle.css" >
<script language="javascript" src="${pageContext.request.contextPath}/scripts/common-validator.js"></script>
<script language="javascript" type="text/javascript" src="scripts/showMenu.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
</head>
<body>
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">

setStatus('<%=SYSTITLE%> - <%=tbbsTopic.getTitle()%>');

window.onload = function(){
resizeImages();
}
</SCRIPT>
<script language="javascript" type="text/javascript" src="template/scripts/topBar.js"></script>
<DIV class="line"></DIV>
<DIV class="list_table_0">
<%=HtmlConst.navMenu(HtmlConst.navClassMenu(new Integer(classId),parentId,grandId,className,parentName,grandName ))%>&gt;&gt;查看文章
</DIV>
<DIV class="line"></DIV>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="bg0">
<tr><td height="20">
<DIV class="list_url">
<img src="images/home.gif" align="absmiddle">
<script language="javascript">copyUrl();</script>
</DIV>
</td>
<td align="right" width="260">
<a href="topic_new.jsp?<%=queryCond %>&action=new"><img alt="发表新主题" src="images/topic.gif" border="0" align="absmiddle" /></a>
&nbsp;&nbsp;
<a href="topic_re.jsp?<%=queryCond %>&action=re"><img alt="回复本主题" src="images/reTopic.gif" border="0" align="absmiddle"/></a>
</td></tr></table>
<%//结贴
List getMarkList = null;
Object[] rsMap = null;
if(action.equals("balance")){
//查询已给分用户	
getMarkList = topicReService.listGetMark(topicId);
%>
<DIV class="line"></DIV>
<!-------------结贴提示开始---------------->
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="3" bgcolor="#006699">
<tr><td height="25">
<span style="color:#ffffff; font-size: 14px;"><p align="center" style="font-weight: bold;">结贴是一种美德</p>
社区结贴你可以分次分页的给每位用户发送积分，发送的同时你的积分随之减少，
如果回帖很多你也可能会在第二页或者第N页继续送分，这将不会影响您之前提交的数据，
直到您送出的分数和你发帖时设定的分数相同时该贴状态显示为&lt;已结贴&gt;状态，
如果您不结贴系统将定期自动结贴，自动结贴虽然不会给回复您主题的用户加分，但是会扣除
您贴子设定的积分数，且可能降低您在社区的信誉值！下面请您在贴子右边的文本框内输入您要送给回帖用户的积分数！<br>
</span>
</td>
</tr></table>
<!-------------结贴提示结束---------------->
<%}%>
<DIV class="line"></DIV>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td><%=HtmlConst.pageJump(totalReCount, pageReSize, pageIndex, pageUrl)%></td>
		<td align="right" height=20>&nbsp;&nbsp;查阅<strong>&nbsp;<%=(tbbsTopic.getTopicViewCount().intValue()+1)%>&nbsp;</strong>次
		&nbsp;&nbsp;回复<strong>&nbsp;<%=tbbsTopic.getTopicReCount() %>&nbsp;</strong>次<strong>
<%if(classStyle==0){
	out.print("&nbsp;&nbsp;<a href=\"topic_page.jsp?"+queryCond+"&classStyle=1&pageIndex="+pageIndex+"\">树型显示</a>");
}else{
	out.print("&nbsp;&nbsp;<a href=\"topic_page.jsp?"+queryCond+"&classStyle=0&pageIndex="+pageIndex+"\">平板显示</a>");
}%>
</strong>&nbsp;&nbsp;<a href="topic_recommend.jsp?<%=queryCond %>">推荐给朋友</a>
&nbsp;&nbsp;<a href="#" onClick="javascript:topicIlike(<%=topicId %>,<%=USER_ID %>);return false;" target="_self">订阅本主题</a>
</td></tr></table>
<%
//读取当前用户的最新信息

%>
<%-- ---------散分求助贴相关提示及控件开始-------- --%>

<%if(action.equals("balance")&&(topicType==4||topicType==6)){	%>
	<table width="100%" border="0" align="center" cellpadding="4" cellspacing="1" class="tab">
	<tr class="tab2"><td height="30">	
	&nbsp;<strong>已经得分的用户有</strong>：
	<% 
		for(int i=0;i<getMarkList.size();i++) {
			
			rsMap = (Object[])getMarkList.get(i);
			remainMark = remainMark.subtract((BigDecimal)rsMap[2]);//剩余可散的分数等于总分减已散分
			out.print(Arguments.getUserInfoLink(Utility.parseInt(rsMap[0].toString()),Utility.trimNull(rsMap[1])));
			out.print("(");
			out.print(rsMap[2]);
			out.print(")&nbsp;&nbsp;");
		}
		if(topicType==6){out.print("<span style=\"float:right; color: #CC0000;\">&lt;该问题已经结贴&gt;</span>");}%>
	</td></tr></table>
<%} %>

<%
/*****结贴控件开始********/
if(action.equals("balance")){
	out.print("<form name=\"giveMark\" id=\"giveMark\" method=\"post\" >");
}
/*****结贴控件结束********/
%>

<%-- ---------散分求助贴相关提示及控件开始-------- --%>	

<%
if(pageIndex==1&&reList.size()==1){
	out.print("<div align=\"center\">暂时无人回复...</div>");
}
int storey = 0;//楼层
TbbsUserInfo tbbsUserInfo = null;
TbbsUserDetail tbbsUserDetail = null;
int reUserType = 0;	//回复对应的用户类型 0：过客，1：普通，2，发帖人

for(int j=0;j<reList.size();j++) //显示回复
{	
	tbbsTopicRe = (TbbsTopicRe)reList.get(j);
	storey = tbbsTopicRe.getStorey().intValue();
	if(classStyle==1&&((topicReId==0&&j>0)||(topicReId!=0&&tbbsTopicRe.getTopicReId().intValue()!=topicReId)))	//树型显示			
	{		
		continue;
	}
	/*****平板文章回复列表开始******/
	//读取回复用户的最新信息
	if(tbbsTopicRe.getUserId().intValue()>0)
	{	
		tbbsUserInfo = userService.load(tbbsTopicRe.getUserId());
		tbbsUserDetail = userService.loadDetail(tbbsTopicRe.getUserId());
		reUserType = 1;
		if(tbbsTopicRe.getUserId().intValue()==tbbsTopic.getUserId().intValue())
		{
			reUserType = 2;
		}
	}
	else
	{
		reUserType = 0;
		tbbsUserInfo = new TbbsUserInfo();		
		tbbsUserDetail = new TbbsUserDetail();
	}	
%>

<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tab" style="margin-bottom: 0px;">
<tr class="tr2">
	<td width="128" height="12">
	<strong>&nbsp;用户:</strong>
	<%=Arguments.getUserInfoLink(tbbsUserInfo.getUserId(),tbbsUserInfo.getLoginId(),tbbsUserInfo.getUserName(),tbbsUserInfo.getIsdelFlag()) %>
	</td>
	<td height="22">
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
			<tr><td align="left">		
			<%=Arguments.getTopicMoodDisplay(tbbsTopicRe.getReMood()) %>
			<strong>
			<%=Arguments.getTopicReLink(tbbsTopicRe,pageIndex) %>
			</strong>
			&nbsp;<span class="smallTxt"><%=HtmlConst.formatDateHtml(tbbsTopicRe.getReAddTime()) %></span>	
			</td><td align="right"><a href="#top" class="smallTxt">TOP</a></td></tr>	
		</table>
	</td>
</tr>
<tr class="tab2">
<td width="128" nowrap="nowrap" valign="top" class="td">
	<!------------------用户信息开始显示------------------->
	<table width="100%" border="0" align="center" cellpadding="1" cellspacing="2">
	<tr>
		<td colspan="2" align="center"><%=Arguments.getUserHeadLink(tbbsUserInfo.getPersonalPic()) %></td>
	</tr>
	<tr>
		<td width="35"><strong>积分:</strong></td>
		<td ><%=Utility.trimNull(tbbsUserInfo.getUserMark()) %></td>
	</tr>
	<tr>
		<td><strong>金币:</strong></td>
		<td><%=Utility.trimNull(tbbsUserInfo.getUserMoney()) %></td>
	</tr>
	<tr>
		<td><strong>信誉:</strong></td>
		<td><%=Utility.trimNull(tbbsUserInfo.getUserCredit()) %></td>
	</tr>
	<tr>
		<td><strong>发帖:</strong></td>
		<td><%=Utility.trimNull(tbbsUserInfo.getUserTopicCount()) %></td>
	</tr>
	</table>
	<!-----------------用户信息结束显示------------------>				
</td>
<td valign="top" class="bg0">
	<!-----------------文章顶部按钮开始------------------>
	<table width="100%" border="0" cellpadding="1" cellspacing="2">
	<tr><td  align="right">
	<span style="float:left">
	<span style=color:#0022aa>[<%if(tbbsTopic.getTopicReId().intValue()==tbbsTopicRe.getTopicReId()) out.print("楼主"); else out.print(storey+"楼"); %>]</span>-&gt;&nbsp;<%=Arguments.getUserInfoLink(tbbsUserInfo.getUserId(),tbbsUserInfo.getLoginId(),tbbsUserInfo.getUserName(),tbbsUserInfo.getIsdelFlag()) %>
	</span>
	<!-- 管理线拉菜单开始 -->
	<DIV class="showMenu" id="Menu_Show_<%=storey%>" >
	<UL>
	<li><a href="topic_edit.jsp?classId=<%=classId %>&topicId=<%=topicId %>&topicReId=<%=tbbsTopicRe.getTopicReId() %>&action=edit" target="_self">编辑主题</A></li>
	<%
	if(tbbsTopic.getTopicReId().intValue()==tbbsTopicRe.getTopicReId().intValue()) //如果当前回复为该主题的内容
	{%>	
		<li><a href="topic_remove.jsp?classId=<%=classId %>&topicId=<%=topicId %>&topicReId=<%=tbbsTopicRe.getTopicReId() %>" title="删除主题" target="_self">删除主题</a></li>
		<%if(topicType==4&&!action.equals("balance")) {%>
			<li><a href="topic_page.jsp?<%=queryCond %>&action=balance" target="_self">结贴给分</a></li>
		<%} %>
		<%if(operatorType==2){%>
			<li><a href="topic_page_manage.jsp?<%=queryCond %>&action=manage" target="_self">主题加(扣)分</a></li>
			<li><%if(tbbsTopic.getTopicPro().intValue()==3){%>
			<a href="topic_page_manage.jsp?<%=queryCond %>&action=nobest" target="_self">解除精品</a>
			<%}else{%><a href="topic_page_manage.jsp?<%=queryCond %>&action=best" target="_self">加为精品</a>
			<%}%></li>
			<li><a href="topic_page_manage.jsp?<%=queryCond %>&action=move" target="_self">移动主题</a></li>
			<li><a href="topic_page_manage.jsp?<%=queryCond %>&action=top" target="_self">置顶主题</a></li>
		<%} %>	
	<%} %>
	</UL></DIV>
	<!-- 管理线拉菜单结束 -->
	<%if(reUserType>0) {%>
		<%=Arguments.getUserWebLink(tbbsUserDetail.getPersonalWeb()) %>
		<%=Arguments.getUserInfoPicLink(tbbsUserInfo.getUserId()) %>
		<%=Arguments.getUserEmailLink(tbbsUserInfo.getUserId()) %>
		<%=Arguments.getAddFriendLink(tbbsUserInfo.getUserId()) %>
		<%=Arguments.getSendMessageLink(tbbsUserInfo.getLoginId()) %>
	<%}%>
	<%=Arguments.getReTopicLink(classId,topicId,tbbsTopicRe.getTopicReId()) %>
	<%=Arguments.getQuoteTopicLink(classId,topicId,tbbsTopicRe.getTopicReId())%>
	<%if(reUserType>0) {%>
		<a onmouseover="showmenu(event,'','Menu_Show_<%=storey%>')" href="#"  onclick="return false;"><img alt="主题管理" src="images/pages/9.gif" border="0"  /></a>
	<%} %>
	</td></tr></table>
	<!-----------------文章顶部按钮结束------------------>
<%
if(tbbsTopic.getTopicReId().intValue()==tbbsTopicRe.getTopicReId().intValue())	//主题内容
	out.print(Arguments.getTopicContent(operatorType,tbbsUserInfo,tbbsTopic,tbbsTopicRe));
else	//回复
	out.print(Arguments.getTopicReContent(operatorType,tbbsUserInfo,tbbsTopicRe.getTopicReId(),tbbsTopicRe.getRePro(),tbbsTopicRe.getReIsDel()));
%>
<%
/*****结贴控件开始********/
if(action.equals("balance")&&topicType==4&&reUserType==1){	
	if(tbbsTopicRe.getGetMark()!=null)
		remainMark = remainMark.add(tbbsTopicRe.getGetMark());
%>
<span style="float:right">
给分：<input name="giveMark_<%=storey%>" type="text" id="giveMark_<%=storey%>" onBlur="checkMark(this);" value="<%=Utility.trimNull(tbbsTopicRe.getGetMark()) %>" size="10" maxlength="10">
<input name="giveRe_<%=storey%>" type="hidden" id="giveRe_<%=storey%>" value="<%=tbbsTopicRe.getTopicReId()%>">
</span>
<%
}
/*****结贴控件结束********/
%>
</td></tr>
</table>
<%} %>
<%-- ---------散分求助贴相关提示及控件开始-------- --%>	
<% if(action.equals("balance")&&(topicType==4 || topicType==6)){ %>
	<table width="100%" border="0" align="center" cellpadding="4" cellspacing="1" class="tab">
	<tr class="tab2"><td height="30">	
	&nbsp;<strong>已经得分的用户有</strong>：
	<% 	
		for(int i=0;i<getMarkList.size();i++) {
			rsMap = (Object[])getMarkList.get(i);
			out.print(Arguments.getUserInfoLink(Utility.parseInt(rsMap[0].toString()),Utility.trimNull(rsMap[1])));
			out.print("(");
			out.print(rsMap[2]);
			out.print(")&nbsp;&nbsp;");
		}
	if(topicType==6){out.print("<span style=\"float:right; color: #CC0000;\">&lt;该问题已经结贴&gt;</span>");}
	else
	{%>		
		<span style="float:right"><button name="btnGiveMark" id="btnGiveMark" class="btn" onClick="javascript:doGiveMark(<%=topicId %>);">确定给分</button></span>
	<%}	%>
	</td></tr></table>
<%} %>
<%
if(topicType==6){
	out.print("<span style=\"float:right; color: #CC0000;\">&lt;该问题已经结贴&gt;</span>");
}
/*****结贴控件开始********/
if(action.equals("balance")){
out.print("</form>");
}
/*****结贴控件结束********/
%>
<%-- ---------散分求助贴相关提示及控件结束-------- --%>
<%-- ---------平板文章列表结束-------- --%>	
<%if(classStyle==1)	//树型显示
{%>
<%-- ---------树型列表开始-------- --%>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="tab">
<tr align="center" class="tr">
<td height="22"><strong>树型列表</strong></td>
<td width="40"><strong>查阅</strong></td>
<td width="40"><strong>回复</strong></td>
<td width="120"><strong>发表时间</strong></td></tr>
<tr class="tab2">
<td height="25">
<%=Arguments.getTopicMoodDisplay(tbbsTopic.getTopicMood()) %>
〖<%=Arguments.getUserInfoLink(tbbsTopic.getUserId(),tbbsTopic.getLoginId()) %>〗
<%=Arguments.getTopicLink(tbbsTopic,pageIndex) %>
<%=Arguments.getTopicHotDisplay(SYSINFO.getIsHottopic().intValue(),SYSINFO.getIsHotre().intValue(),tbbsTopic.getTopicViewCount().intValue(),tbbsTopic.getTopicReCount().intValue()) %>
</td><td align="center" class="smallTxt">
<%=tbbsTopic.getTopicViewCount()+1 %>
</td><td align="center" class="smallTxt">
<%=tbbsTopic.getTopicReCount() %>
</td><td align="center" class="smallTxt">
<%=HtmlConst.formatDateHtml(tbbsTopic.getTopicAddTime()) %>
</td></tr>
<!-------------树型回复列表开始---------------->
<%
String trClass = "";
for(int i=0;i<reList.size();i++)	//从第一条回复开始
{	
	tbbsTopicRe = (TbbsTopicRe)reList.get(i); 
	if(tbbsTopic.getTopicReId().intValue()==tbbsTopicRe.getTopicReId().intValue())
		continue;
	if(topicReId==tbbsTopicRe.getTopicReId().intValue()||(pageIndex>1&&i==0))	//如果当前点击的是某个回复或者是跳转到第二页
		trClass = "tab3";
	else
		trClass = "bg0";	
	%>	
<tr class="<%=trClass %>">
	<td height="25" colspan="4">
		<%=Arguments.getTopicReTreeDisplay(i,reList.size()) %>
		<%=Arguments.getTopicMoodDisplay(tbbsTopicRe.getReMood()) %>〖<%=Arguments.getUserInfoLink(tbbsTopicRe.getUserId(),tbbsTopicRe.getLoginId()) %>〗<%=Arguments.getTopicReLink(tbbsTopicRe,pageIndex) %>		
		<%=HtmlConst.formatDateHtml(tbbsTopicRe.getReAddTime()) %>
		&nbsp;<i><%=Arguments.getTopicLenDisplay(classId,tbbsTopicRe.getTopicId().intValue(),tbbsTopicRe.getTopicReId().intValue(),tbbsTopicRe.getReLen().intValue(),true) %></i>
	</td>	
</tr>
<%} %>
<%-- ----------树型列表结束-------- --%>
<!-------------讨论区风格回复开始---------------->
</table>
<%}%>				
<DIV class="line"></DIV>
<DIV>
<%=HtmlConst.pageJump(totalReCount,pageReSize, pageIndex, pageUrl)%>
</DIV>
<DIV class="line"></DIV>
<script language="javascript" type="text/javascript" src="scripts/topicPage.js"></script>
<SCRIPT language="javascript">
var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT,false);

function doSubmit() 
{	
	display();
	form = document.theform;
	if(!validateForm(form))
		return false;
		
    var obj = {};    
   
	obj[Buffalo.BOCLASS] = "java.util.HashMap";
	
	var loginIdOld = "<%=userLogin.getLoginId()%>";
	var passwordOld = "<%=userLogin.getPassword()%>";	
	var userId = <%=userLogin.getUserId()%>;
		
	var loginId = trim($F('loginId'));
	var password = $F('password');
	var loginIp = "<%=request.getRemoteAddr()%>";	

	obj.userId = userId;	
	obj.loginId = loginId;
	obj.topicAddIp = loginIp;
	
	obj.classId = <%=classId%>;
	obj.classParentId = <%=parentId%>;
	obj.grandId = <%=grandId%>;		
	
	obj.topicId = <%=topicId%>;
	obj.title =  $F('title').trimHTML();

	obj.topicStyleList = " ,0";	
	obj.content =  htmlEncoder($F('content'));	
	var url = "topic_post.jsp?classId=<%=classId%>&topicId=<%=topicId%>";

	var successFlag = true;	//成功登陆标志
	if(loginId!="")		//以用户方式发表回复
	{		
		if(loginId!=loginIdOld)	//原来已经登陆过；或者现在输入了用户名现在修改了登陆名要重新登陆
		{
			successFlag = false;
			buffalo.remoteCall("userServiceAjaxService.userLoginAjax",[loginId,password,loginIp], function(reply) 
		    {
		       	var ret = reply.getResult();
		       	var params = parseAjaxReturn(ret);			
		       	if(params=="error")
		       	{
		       		sl_alert(ret);
		       		successFlag = false;
		       	}
		       	else
		       	{		
		       		userId = getParamValue(params,"userId");	       		
		       		loginId = getParamValue(params,"loginId");	       	
		       		successFlag = true;
		        }  
		       	    	
		    });	 	
    	}		
	}
	else //以游客方式发表回复
	{
		if(loginIdOld!="")	//原来已经登陆过，但是现在要以游客方式发表回复
		{
			userId = 0;
			loginId = "";
		}
	}
	if(!successFlag) return false;	
	
	obj.userId = userId;	
	obj.loginId = loginId;	
	
	buffalo.remoteCall("topicServiceAjaxService.doReTopic",[obj], function(reply){
		var ret = reply.getResult();
		ajaxSubmit(ret,"回复成功！","reload");        
	});
}

var remainMark = <%=remainMark%>;

function checkMark(obj)
{
	if(!obj.value.isEmpty())
	{
		if(!sl_checkIntValue(obj,"分数",-1,1)) return false;			
	}	
}

function doGiveMark(topicId)
{	
	var markObjs = Form.getInputs(document.giveMark,"text");
	if(markObjs.length==0)
	{
		sl_alert("该页没有可给分回复！");
		return false;
	}	
	var tempMark = remainMark;	
	var markObjs = Form.getInputs(document.giveMark,"text");
	for(var i=0;i<markObjs.length;i++)
	{
		mark = markObjs[i];
		if(trim(mark.value)!="")
		{				
			tempMark = tempMark - parseInt(mark.value);
		}
	}		
	if(tempMark<0)
	{
		sl_alert("该页面累计送分超过了剩余可用积分，请您重新调整！");				
		return false;
	}
	else if(tempMark==remainMark)
	{
		sl_alert("请您先给分！");				
		return false;
	}
	//所有验证通过，提交数据		
	var obj = {};    
    obj[Buffalo.BOCLASS] = "java.util.HashMap";   
		
	for(var i=0;i<markObjs.length;i++)
	{	
		mark = markObjs[i];
		point = mark.name.indexOf("_")+1;
		storey = mark.name.substring(point);
		reId = $F("giveRe_"+storey);
		if(!isNull(mark.value))	//数据不为空的才提交
		{			
			 obj[reId] = mark.value;	
		}
	}		
    
	buffalo.remoteCall("topicReServiceAjaxService.doGiveMark",[topicId,obj], function(reply) 
    {
        var ret = reply.getResult();
       	ajaxSubmit(ret,"");        
    });   
}
</SCRIPT>
<form name="theform" id="theform" method="post" onSubmit="return validateForm(this);" action="topic_post.jsp">
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="1" class="tab">
	<tr>
		<td width="128"  class="tab1"><strong>用户</strong></td>
		<td class="bg2"><input name="loginId" type="text" id="loginId" value="<%=LOGIN_ID%>" size="20" maxlength="20" title="清空用户名则以过客形式发表回复" /></td></tr>
	<tr>
		<td  class="tab1"><strong>密码</strong></td>
		<td class="bg2"><input name="password" type="password" id="password" value="<%=userLogin.getPassword()%>" size="20" maxlength="50" />
		<input name="passwordOld" type="hidden" id="passwordOld" value="<%=userLogin.getPassword()%>" size="20" maxlength="50" /></td>
	</tr>
	<tr>
		<td class="tab1"><strong>标题</strong></td>
		<td class="bg2"><input  name="title" type="text" id="title" size="60" maxlength="100" value=""/></td>
	</tr>
	<tr>
		<td valign="top" class="tab1"><strong>正文</strong></td>
		<td class="bg2"><textarea name="content" id="content" cols="80" rows="8"></textarea><script language="javascript">textAreaEx("content",8)</script></td>
	</tr>
	<tr>
		<td height="30" align="middle" colspan="2" class="tab1">	
			<input name="btnSubmit" type="button" class="btn" id="btnSubmit" value="发表回复" onClick="javascript:doSubmit();"/></td>
	</tr>
</table>
</form>
<%=COPYRIGHTFOOT%>
<%@ include file="../common/foot.inc"%>
</body>
</html>